import streamlit as st
import pandas as pd
from services import db

st.title("查看/管理员工信息")

db.init_db()

data = db.get_all_employees()
df = pd.DataFrame(data,columns=["工号","姓名","部门","备注","创建时间","样本数"])
st.dataframe(df,use_container_width=True)

st.markdown("---")
st.subheader("操作员工信息")

# 删除员工
with st.form("delete_employee_form"):
    emp_id_del = st.text_input("输入工号删除员工", key="delete_emp_id")
    delete_submit = st.form_submit_button("删除员工")
    if delete_submit:
        if emp_id_del:
            ok,msg = db.delete_employee(emp_id_del)
            if ok:
                st.success(msg)
            else:
                st.error(msg)
        else:
            st.warning("请先输入工号")

# 更新备注
with st.form("update_note_form"):
    emp_id_update = st.text_input("输入工号更新备注", key="update_emp_id")
    new_note = st.text_input("新备注", key="new_note_input")
    update_submit = st.form_submit_button("更新备注")
    if update_submit:
        if emp_id_update:
            ok,msg = db.update_employee(emp_id_update,note=new_note)
            if ok:
                st.success(msg)
            else:
                st.error(msg)
        else:
            st.warning("请先输入工号")
